// pagesDoctor/patientDetail/index.js
import {
  ApiGetOrderInfo,
  ApiGetOrderList,
  ApiCaseHistorySearch
} from '../../api/docIndex'
import {
  dataValue
} from './data.js'
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    $path: app.globalData.$path,
    active: '问诊记录',
    statusFormatter: [{
      label: '待支付',
      value: '1'
    }, {
      label: '进行中',
      value: '2'
    }, {
      label: '已完成',
      value: '3'
    }, {
      label: '已取消',
      value: '4'
    }, {
      label: '已评价',
      value: '5'
    }, {
      label: '退款中',
      value: '6'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      patientData: JSON.parse(options.data),
      dataValue: dataValue.content
    })
    this.getOrderInfo(this.data.patientData.patient_id)
  },


  enterConsultationRoom(e) {
    const item = e.currentTarget.dataset.v
    const ops = {
      icon: item.icon,
      id: item.id,
      doctor_id: item.doctor_id,
      doctor_name: item.doctor_name,
      department_name: item.department_name,
      consultation_order_id: item.id,
      status: item.status,
      finish_time: item.finish_time,
      comment: item.comment,
      statusS: item.statusS,
      order_time: item.order_time,
      status: item.status,
      finish_time: item.finish_time,
      cancel_time: item.cancel_time,
      patient_id: item.patient_id
    }

    wx.setStorageSync('messageDetail', ops)
    wx.navigateTo({
      url: `/pagesDoctor/messageDetail/index?contact=${JSON.stringify(ops)}`,
    })
  },
  //进入问诊间
  /*  enterConsultationRoom(e) {
     console.log(e)
     let item = e.currentTarget.dataset.v
     const ops = {
       icon: item.icon,
       id: item.id,
       doctor_id: item.doctor_id,
       doctor_name: item.doctor_name,
       department_name: item.department_name,
       consultation_order_id: item.id,
       status: item.status,
       finish_time: item.finish_time,
       comment: item.comment,
       statusS: item.statusS,
       order_time: item.order_time,
       status: item.status,
       finish_time: item.finish_time,
       cancel_time: item.cancel_time
     }
     console.log('opsopsopsops', ops)
     wx.setStorageSync('opsPatient', ops)
     wx.navigateTo({
       url: `/pagesDoctor/messageDetail/index`,
     })
     /*   contact={"icon":"files/admin/20241129/20241129131303_20241129.jpg","doctor_id":36,"doctor_name":"内科医生","department_name":"消化内科","consultation_order_id":53} 
   }, 
   */


  checkStatus(item) {
    this.data.statusFormatter.forEach(statusItem => {
      if (item.status == statusItem.value) {
        item.statusLabel = statusItem.label
      }
    })
  },
  getOrderInfo(id) {
    wx.showLoading({
      title: '加载中',
    })
    ApiGetOrderList({
      patient_id: id
    }).then(res => {
      res.data.forEach(item => {
        this.checkStatus(item)
      })
      this.setData({
        orderListData: res.data,
        orderInfo: res.data[0]
      })
      wx.hideLoading()
    })
  },

  onChange(e) {
    this.setData({
      active: e.detail.title
    })
    if (e.detail.title == '基本信息') {

    } else if (e.detail.title == '问诊记录') {

    } else {
      //电子病历的方法
      this.getCaseHistoryList()
    }
  },

  getCaseHistoryList() {
    wx.showLoading({
      title: '加载中',
    })
    ApiCaseHistorySearch({
      patient_id: this.data.patientData.patient_id
    }).then(res => {
      this.setData({
        recordArr: res.data
      })
      wx.hideLoading()
    })
  },

  recordDetailClick(e) {
    wx.navigateTo({
      url: `/pagesDoctor/medicalRecordsSearchDetail/index?data=${JSON.stringify(e.currentTarget.dataset.v)}`,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})